<% content_for(:head) do %>
  <%= calendar_date_select_includes "default" %>
<% end %>

<div class="admin goals">
  <div class="section header dark-50">
    <h2 class="light"><%= @goal ? "Edit" : "Add" %> Goals</h2>
  </div>
  
  <div class="entry">
    <% form_remote_tag(
        :url => { 
          :action     => "goals_submit" },
        :complete => 
          "Submit.genericAfterSubmit",
        :before => "Submit.genericSubmit();"
        ) do %>
      <div class="top">
        <%= default_text_field_tag("goal", "name", @goal) %>
        <%= hidden_field_tag(
              "goal_id", 
              @goal ? @goal.id : nil) %>
      </div>
      <div class="main">
        <div>
          <%= default_text_field_tag("goal", "summary", @goal) %>
          <br/><br/>
          <%= default_text_area_tag("goal", "description", @goal) %>
          <br/><br/>
          
          <table>
            <tr>
              <td>
                Priority: 
              </td>
              <td>
                <%= default_text_field_tag("goal", "priority", @goal) %>
              </td>
            </tr>
            <tr>
              <td>
                Begin: 
              </td>
              <td>
                <%= calendar_date_select_tag(
                      "goal_begin_at", 
                      @goal ? @goal.begin_at : "", 
                      :class => "default") %>
              </td>
            </tr>
            <tr>
              <td>
                Finish: 
              </td>
              <td>
                <%= calendar_date_select_tag(
                      "goal_end_at", 
                      @goal ? @goal.end_at : "", 
                      :class => "default" ) %>
              </td>
            </tr>
            <tr>
              <td>
                Recurs every: 
              </td>
              <td>
                <% interval_disabled = @goal ? (!@goal.interval && !@goal.interval_unit) : false %>
                
                <%= text_field_tag(
                      "goal_interval", 
                      @goal ? @goal.interval : "Interval", 
                      :class => "default goal_interval #{"dormant" if !@goal}",
                      :autocomplete => "off",
                      :disabled => interval_disabled ) %>
                <%= select(
                      "goal", 
                      "interval_unit", 
                      Goal::GOAL_INTERVAL_UNITS, 
                      {}, 
                      { :class => "default", 
                        :name => "goal_interval_unit",
                        :disabled => interval_disabled } ) %>
                
                <span style="margin-left: 20px;">
                  <%= check_box_tag("goal_no_interval",
                        "1",
                        interval_disabled,
                        :style => "vertical-align: middle;", 
                        :onclick => "Goals.selectNoInterval();" ) %> 
                  <span onclick="$('goal_no_interval').checked = !$('goal_no_interval').checked; Goals.selectNoInterval();">No recurrence</span>
                </span>
              </td>
            </tr>
          </table>
        </div>  
      </div>
      <div class="bottom">
        <div id="errors-container" class="errors-container"></div>
        <div class="submit">
          <%= submit_tag "Save", :class => "default submit" %>  
        </div>
        <br class="clear"/>
      </div>
    <% end %>
  </div>
  <br/>
  
  <div class="section header dark-50">
    <h2 class="light">Recent Goals</h2>
  </div>
  <div class="section body dark-25">
    <% @goals.each do |goal| %> 
      <%= link_to( h(goal.name), admin_goals_edit_url(:id => goal.id, :type => goal.class.to_s) ) %>
      <br/>
    <% end %>
  </div>
</div>